package com.voxel.sense.infomsg.view;

import android.content.Context;
import android.widget.TextView;

import com.github.mikephil.charting.components.MarkerView;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.highlight.Highlight;
import com.github.mikephil.charting.utils.MPPointF;
import com.voxel.sense.infomsg.R;
import com.voxel.sense.infomsg.data.bean.RealDataBean;

/**
 * Created by ChenYiYao on 2017/11/15.
 */

public class MyChartMarker extends MarkerView {
    /**
     * Constructor. Sets up the MarkerView with a custom layout resource.
     *
     * @param context
     * @param layoutResource the layout resource to use for the MarkerView
     */
    private TextView textView;

    private boolean isReverse = true;

    public MyChartMarker(Context context, int layoutResource) {
        super(context, layoutResource);
        textView = (TextView) findViewById(R.id.tv_desc);
    }


    @Override
    public void refreshContent(Entry e, Highlight highlight) {
        Object data = e.getData();
        if (data instanceof String[]) {

            String[] strs = (String[]) data;
            textView.setText(strs[1]);

        } else if (data instanceof RealDataBean) {
            RealDataBean bean = (RealDataBean) data;
            textView.setText(bean.getValue() + "(" + bean.getParamUnit() + ")");
        }
        super.refreshContent(e, highlight);
    }

    @Override
    public MPPointF getOffset() {
        MPPointF mpPointF = super.getOffset();
        mpPointF.x = -(getWidth() / 2);
        mpPointF.y = -getHeight();
        return mpPointF;
    }
}

